package org.example.tree;

/**
 * @author liyishan
 * @date 2024/7/29 10:04
 * @apiNote
 */

public class Test01022SumRootToLeaf {
    public int sumRootToLeaf(TreeNode root) {
        return dfs(root,0);
    }
    public int dfs(TreeNode root,int val){
        if(root == null){
            return 0;
        }
        val = (val << 1) | root.val;
        if(root.left == null && root.right == null){
            return val;
        }
        return dfs(root.left,val)+dfs(root.right,val);

    }
}
